package com.lovo.ssc.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lovo.csc.dto.PrepayDto;
import com.lovo.ssc.bean.Rechargerecord;
import com.lovo.ssc.service.ILevelService;
import com.lovo.ssc.service.IRechargerecordService;
import com.lovo.ssc.service.impl.LevelServiceImpl;
import com.lovo.vo.TopUpVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

/**
 * <p>
 * 用户等级表，不同等级对应不同的折扣率 前端控制器
 * </p>
 *
 * @author lovo
 * @since 2022-07-11
 */
@RestController
@RequestMapping("/level")
@Api(tags = "预存款接口(刘洪刚)")
public class LevelController {
    @Autowired
    private LevelServiceImpl levelService;
    @Autowired
    private IRechargerecordService rechargerecordService;


@ApiOperation(value = "充值预存款")
@PostMapping("sendMoney")
public boolean sendMoney(TopUpVO topUpVO){
    System.out.println("进入充值");
    System.out.println(topUpVO);

    if (levelService.sendMoney(topUpVO)){
        return true;
    }
    return false;
}



//    @GetMapping("TestMoney")
//    public void TestMoney(PrepayDto prepayDto) throws IOException {
//        levelService.getDiscount(prepayDto);
//    }
    @ApiOperation(value = "查询充值状态")
    @GetMapping("findRechargeState")
    public String findRechargeState(){
        if (levelService.findRechargeState()){
            System.out.println(levelService.findRechargeState());
            return "充值成功";
        }else {
            System.out.println(levelService.findRechargeState());
            return "充值中";
        }
    }
    @ApiOperation(value = "查询预存款余额")
    @GetMapping("findMoney")
    public Double findMoney(){

        return levelService.findMoney();
    }

    @ApiOperation(value = "查询预存款收支记录")
    @GetMapping("findRechargerecord")
    public List<Rechargerecord> findRechargerecord(){

        QueryWrapper qw = new QueryWrapper();
        qw.orderByDesc("recordId");
        List<Rechargerecord> list = rechargerecordService.list(qw);
        return list;
    }
}
